<?php



/**
 * 工厂类
 *
 */
class JL_factory{
	
	
	static private $class_list = array(
							'JL_GD2'             =>     'jl_gd2.cls',
							'JL_lasting_var'     =>     'jl_lasting_var.cls',
							'JL_mysql_table'     =>     'jl_mysql_table.cls',
							'JL_page'            =>     'jl_page.cls',
							'JL_upload'          =>     'jl_upload.cls'
							);
	
	
	
	
	public function __construct(){
		$this->JL_factory();
	}
	
	public function JL_factory(){

	}
	
	/**
	 * 构造单例对象
	 *
	 * @param unknown_type 对象名
	 * @param unknown_type 类名
	 * @param unknown_type 文件地址
	 * @param unknown_type 构造方法参数
	 * @return 单例类对象
	 */
	static public function build_obj_only($obj_name,$class_name,$file_path,$parameter_arr = array()){
		
		if (isset($GLOBALS['JL_factory_obj_list'][$obj_name])) {
			return $GLOBALS['JL_factory_obj_list'][$obj_name];
		}
		
		
		$obj = $this->build_obj($class_name,$file_path,$parameter_arr);
		$GLOBALS['JL_factory_obj_list'][$obj_name] = $obj;
		return $obj;
		
	}
	
	/**
	 * 构造对象
	 *
	 * @param unknown_type 类名
	 * @param unknown_type 文件地址
	 * @param unknown_type 构造方法参数
	 * @return 类对象
	 */
	static public function build_obj($class_name,$file_path,$parameter_arr = array()){
		include_once($file_path);
		$parameter = '';
		
		foreach ($parameter_arr as $value){
			$parameter .= $value.',';
		}
		$parameter = trim($parameter,',');
		$obj = null;
		$obj = new $class_name($parameter);
		
		return $obj;
	}
	
	/**
	 * 控制器的工厂方法
	 *
	 * @param unknown_type $class_file_path
	 * @return unknown
	 */
	static public function getController($class_file_path){
		
		$class_path_arr = explode('.',$class_file_path);
		
		include_once(ROOT_DIR.'/'.$class_path_arr[0].'/'.$class_path_arr[1].'/'.$class_path_arr[2].'.php');
		
		return new $class_path_arr[2]();

	}
	
	static public function getClassObject($class_file_path){

		$class_path_arr = explode('.',$class_file_path);
		
		include_once(ROOT_DIR.'/'.$class_path_arr[0].'/'.$class_path_arr[1].'/'.$class_path_arr[2].'.php');
		
		return new $class_path_arr[2]();
	}
	
	static public function get_JL_class($class_name){
		if (!empty($this->class_list[$class_name])) {
		
			include_once(JL_ROOT.'/'.$this->class_list[$class_name].'.php');
			
			return new $class_name();
		}else {
			return null;
		}
		
		
		
	}
	
	static public function get_JL_GD2($width,$height,$antialias=false){
		
			
			$class_flie_name = 	self::$class_list['JL_GD2'];
			
			include_once(JL_ROOT.'/'.$class_flie_name.'.php');
			
			return new JL_GD2($width,$height,$antialias=false);
	}
	
	static public function get_JL_lasting_var($name){
			
			$class_flie_name = 	self::$class_list['JL_lasting_var'];
			
			include_once(JL_ROOT.'/'.$class_flie_name.'.php');
			
			return new JL_lasting_var($name);
	}
	
	static public function get_JL_mysql_table($table_name = ''){
			
			$class_flie_name = 	self::$class_list['JL_mysql_table'];
			
			include_once(JL_ROOT.'/'.$class_flie_name.'.php');
			
			return new JL_mysql_table($table_name);
	}
	
	static public function get_JL_page(){
			$class_flie_name = 	self::$class_list['JL_page'];
			
			include_once(JL_ROOT.'/'.$class_flie_name.'.php');
			
			return new JL_page();
	}
	
	static public function get_JL_upload($dir, $types, $ext_type='', $size_mini = 1000,$size_max = 1000000){
			$class_flie_name = 	self::$class_list['JL_upload'];
			
			include_once(JL_ROOT.'/'.$class_flie_name.'.php');
			
			return new JL_upload($dir, $types, $ext_type='', $size_mini = 1000,$size_max = 1000000);		
		
	}

	
	
	
	
	
	
}



?>
